<div class="row">
	<div class="col-md-12">
		<ol class="breadcrumb">
			<li>
				<a href="#" onclick="toHome()">
					主页
				</a>
			</li>
			<li>
				<a href="#" class="toList" onclick="toExchangeList()">
					通兑卡列表
				</a>
			</li>
			<li class="active">
				通兑卡详情
			</li>
		</ol>
	</div>
</div>
<form role="form" class="form-horizontal">
	<div class="row page-cont">
		<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 cont-top">
			<div class="panel panel-white">
				<div class="panel-heading">
					<h4 class="panel-title">
						<span class="title-text">通兑卡查看</span>
					</h4>
					<div class="panel-tools">
						<div class="dropdown">
							<a data-toggle="dropdown" class="btn btn-xs dropdown-toggle btn-transparent-grey">
								<i class="fa fa-cog"></i>
							</a>
							<ul class="dropdown-menu dropdown-light pull-right" role="menu">
								<li>
									<a class="panel-collapse collapses" href="#"><i class="fa fa-angle-up"></i> <span>折叠</span> </a>
								</li>
								<li>
									<a class="panel-expand" href="#">
										<i class="fa fa-expand"></i> <span>全屏</span>
									</a>
								</li>
							</ul>
						</div>
						<a class="btn btn-xs btn-link panel-close" href="#">
							<i class="fa fa-times"></i>
						</a>
					</div>
				</div>
				<div class="panel-body">
					<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">通兑卡码</label>
					    <div class="col-sm-5">
					      <input type="text" class="form-control" id="cardCode" />
					    </div>
				  	</div>
					<div class="form-group panel-cont">
					    <label for="couponIntro" class="col-sm-2 control-label">通兑卡密码</label>
					    <div class="col-sm-5">
					      <input type="text" class="form-control" id="cardPwd" />
					    </div>
				  	</div>
					<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">内容</label>
					    <div class="col-sm-5">
					      <input type="text" class="form-control" id="cardContent" />
					    </div>
				  	</div>
				  	<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">兑换时间</label>
					    <div class="col-sm-5">
					      <input type="text" class="form-control" id="exchangeTime" />
					    </div>
				  	</div>
				  	<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">状态</label>
					    <div class="col-sm-5">
					      <input type="text" class="form-control" id="cardStatus" />
					    </div>
				  	</div>
				  	<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">创建时间</label>
					    <div class="col-sm-5">
					      <input type="text" class="form-control" id="createTime" />
					    </div>
				  	</div>
				  	<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">创建操作人员</label>
					    <div class="col-sm-5">
					      <input type="text" class="form-control" id="createMan" />
					    </div>
				  	</div>
				  	<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">更新时间</label>
					    <div class="col-sm-5">
					      <input type="text" class="form-control" id="updateTime" />
					    </div>
				  	</div>
				  	<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">更新操作人员</label>
					    <div class="col-sm-5">
					      <input type="text" class="form-control" id="updateMan" />
					    </div>
				  	</div>
				  	<div id="couponList">

				  	</div>
				</div>
			</div>
		</div>
	</div>
</form>
<script>
	
	/***************************************变量***************************************/
	var token = MXCookie.get("token",token);  // 登陆token;
	var username = GetQueryString("username"); // 用户名		
	/***************************************事件***************************************/
	datePicker($("#startDate"));  // 开始时间
	datePicker($("#endDate"));    // 结束时间
	$("input").attr("readonly","readonly");



	/***************************************函数***************************************/	
	var str = '<div class="coupon-cont">'+
			'<hr style="height:1px;border:none;border-top:1px solid #555555;" />'+
			'<div class="form-group panel-cont">'+
			   '<label class="col-sm-2 control-label">优惠券名称</label>'+
			    '<div class="col-sm-5">'+
			      '<input type="text" class="form-control coupon-name" />'+
			    '</div>'+
		  	'</div>'+
			'<div class="form-group panel-cont">'+
			    '<label for="couponIntro" class="col-sm-2 control-label">优惠券适用场景</label>'+
			    '<div class="col-sm-5">'+
			      '<input type="text" class="form-control coupon-apply" />'+
			   '</div>'+
		  	'</div>'+
			'<div class="form-group panel-cont">'+
			    '<label class="col-sm-2 control-label">最大价格</label>'+
			    '<div class="col-sm-5">'+
			      '<input type="text" class="form-control max-price" />'+
			   '</div>'+
			    '<span class="col-sm-4 tips">'+
			    	'<i class="fa fa-info-circle"></i>'+
			    	'影票价值大于此输入数值将不可使用'+
			    '</span>'+
		  	'</div>'+
		  	'<div class="form-group panel-cont">'+
			    '<label class="col-sm-2 control-label">优惠券数量</label>'+
			    '<div class="col-sm-5">'+
			      '<input type="text" class="form-control coupon-number" />'+
			    '</div>'+
		  	'</div>'+
		  	'<div class="form-group panel-cont">'+
			    '<label class="col-sm-2 control-label">介绍</label>'+
			    '<div class="col-sm-5">'+
			      '<input type="text" class="form-control coupon-intro" />'+
			    '</div>'+
		  	'</div>'+
		  	'<div class="form-group panel-cont">'+
			    '<label class="col-sm-2 control-label">开始日期</label>'+
			    '<div class="col-sm-5">'+
			      '<input type="text" class="form-control start-date" />'+
			    '</div>'+
		  	'</div>'+
		  	'<div class="form-group panel-cont">'+
			    '<label class="col-sm-2 control-label">结束日期</label>'+
			    '<div class="col-sm-5">'+
			      '<input type="text" class="form-control end-date" />'+
			    '</div>'+
		  	'</div>'+
		  	'<div class="form-group panel-cont">'+
			    '<label class="col-sm-2 control-label">优惠券限制的影片</label>'+
			    '<div class="col-sm-5">'+
			      '<input type="text" class="form-control limit-film" />'+
			    '</div>'+
		  	'</div>'+
		  	'<div class="form-group panel-cont">'+
			    '<label class="col-sm-2 control-label">优惠券限制的影院</label>'+
			    '<div class="col-sm-5">'+
			      '<input type="text" class="form-control limit-cinema" />'+
			    '</div>'+
		  	'</div>	'+
			'<div class="form-group panel-cont">'+
			   '<label class="col-sm-2 control-label">优惠券限制的城市</label>'+
			    '<div class="col-sm-5">'+
			      '<input type="text" class="form-control limit-city" />'+
			    '</div>'+
		  	'</div>'+						  				  			
			'</div>';
  	// 获取详情
	$.ajax({
		url: localStorage.grobalUrl + "/discount/viewExchangeCardList",
		type: "post",
		async:false,
		data:{
			username: username,
			token: token,
			id: $(".pageAdd").attr("data-id")
		},
		success: function(data){
			console.log(data);
			if(data.errCode == "00005"){
				tips("请重新登陆");
				setTimeout(function(){
					window.location.href = "login_login.html";
				},500);
			}else if(data){
				// 通兑卡详情
				var exchangeVal = data.exchangeCard;  
				$("#cardCode").val(exchangeVal.card_no);
				$("#cardPwd").val(exchangeVal.password);
				$("#cardContent").val(exchangeVal.content);
				$("#exchangeTime").val(exchangeVal.use_time);
				if(exchangeVal.status == "DELETED"){
	            	$("#cardStatus").val("已删除");
	            }else if(exchangeVal.status == "NOT_USE"){
	            	$("#cardStatus").val("未兑换");
	            }else{
	            	$("#cardStatus").val("已兑换");
	            }
	            $("#createTime").val(exchangeVal.create_time);				
	            $("#createMan").val(exchangeVal.create_by);				
	            $("#updateTime").val(exchangeVal.update_time);				
	            $("#updateMan").val(exchangeVal.update_by);				

	            // 优惠券详情
				var couponVal = data.couponVoList;    
				if(couponVal){
					for(var i = 0; i< couponVal.length; i ++){
						$("#couponList").append(str);
						var couponCont = couponVal[i];
						$(".coupon-name").eq(i).val(couponCont.name);
						if(couponCont.prefix == "EXCHANGE_"){
							$(".coupon-apply").eq(i).val("通兑券");
						}else{
							$(".coupon-apply").eq(i).val("红包");
						}
						$(".max-price").eq(i).val(couponCont.maximum_price);
						$(".coupon-number").eq(i).val(couponCont.point);
						$(".coupon-intro").eq(i).val(couponCont.introduction);
						$(".start-date").eq(i).val(couponCont.begin_date);
						$(".end-date").eq(i).val(couponCont.end_date);
						if(couponCont.rangeFilmName == null){
							$(".limit-film").eq(i).val("不限制");
						}else{
							$(".limit-film").eq(i).val(couponCont.rangeFilmName);
						}
						if(couponCont.rangeCinemaName == null){
							$(".limit-cinema").eq(i).val("不限制");
						}else{
							$(".limit-cinema").eq(i).val(couponCont.rangeCinemaName);
						}						
						if(couponCont.rangeCityName == null){
							$(".limit-city").eq(i).val("不限制");
						}else{
							$(".limit-city").eq(i).val(couponCont.rangeCityName);
						}						
					}
					$("input").attr("readonly","readonly");
				}
			}			
		},
		error: function(err){
			console.log(err);
		}
	});
	
</script>
